package Thinh.thinh.action;

import java.util.List;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import Thinh.thinh.dao.SaleDaoHibernate;
import Thinh.thinh.dao.UserDao;
import Thinh.thinh.model.User;
import Thinh.thinh.service.UserService;

import com.opensymphony.xwork2.ActionSupport;


/**
 * Controller class for actions involving
 * a VVUser.
 * @author brucephillips
 *
 */

public class UserAction extends ActionSupport 
{
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
	private Log logger = LogFactory.getLog(this.getClass());
	private UserDao userDao;
	//private SaleDaoHibernate SaleDao ;
	private User User;
	private List<User> Users;


   
    public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}

	/**
     * Handles actions involving saving 
     * a new or changed VVUser object.
     * Creates or updates vVUser instance
     * field.
     * @return success
     */
    public String save()
    {
    	logger.debug("in method save");
    	
        if (User.getId() == null)
        {
        	userDao.create(User);
        }
        else
        {
        	userDao.update(User);
        }
        return SUCCESS;
    }

    /**
     * Handles delete VVUser action.
     * Deletes vVUser instance field.
     * @return success
     */
    public String delete()
    {
    	logger.debug("in method delete");
        
    	if (User != null && User.getId() != null)
        {
        	logger.debug("VVUser ID is " + User.getId() );
            
        }
    	userDao.delete(User);
    	
        return SUCCESS;
    }

    /**
     * Handles list all VVUser objects action.
     * Sets vVUsers instance field to all
     * VVUser objects.
     * @return
     */
    public String list()
    {
       Users = userDao.findAll();
      // SaleDao.findAll();
    	System.out.print(Users);
        return SUCCESS;
        
    }

    @Override
    public String input()
    {
    	logger.debug("in method input");
    	
    	if (User != null && User.getId() != null)
        {
        	logger.debug("VVUser ID is " + User.getId() );
            User = userDao.findById(User.getId());
        }
        return INPUT;
    }

	

	public User getUser() {
		return User;
	}

	public void setUser(User vVUser) {
		this.User = vVUser;
	}

	public List<User> getUsers() {
		return Users;
	}

	public void setUsers(List<User> vVUsers) {
		this.Users = vVUsers;
	}


 
}
